package com.iplay.实战java高并发程序设计.chapter2;

/**
 * @author dangwu
 * @since 2021/4/30 4:01 下午
 */
public class NoVisibility {
    volatile private static boolean ready;
    private static int number;

    private static class ReaderThread extends Thread{
        @Override
        public void run() {
            while (!ready);
            System.out.println(number);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        new ReaderThread().start();
        Thread.sleep(1000);
        number = 42;
        ready = true;
        Thread.sleep(5000);

    }
}
